﻿<UserControl x:Class="Waf.BookLibrary.Library.Presentation.Views.BookView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:c="clr-namespace:Waf.BookLibrary.Library.Presentation.Converters"
    xmlns:p="clr-namespace:Waf.BookLibrary.Library.Presentation.Properties"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:waf="http://waf.codeplex.com/schemas"
    xmlns:vm="clr-namespace:Waf.BookLibrary.Library.Applications.ViewModels;assembly=Waf.BookLibrary.Library.Applications"
    mc:Ignorable="d" d:DataContext="{d:DesignData Source=../DesignData/SampleBookViewModel.xaml}"
    MinWidth="250" MinHeight="270" IsEnabled="{Binding IsEnabled}"
    waf:ValidationHelper.IsEnabled="true" waf:ValidationHelper.IsValid="{Binding IsValid, Mode=OneWayToSource}">

    <Grid Margin="0,0,22,11">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Label Content="{x:Static p:Resources.TitleMenu}" Target="{Binding ElementName=titleBox}" Grid.Column="0" Grid.Row="0"/>
        <TextBox x:Name="titleBox" Text="{Binding Book.Title, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
                 MaxLength="100" Grid.Column="1" Grid.ColumnSpan="2" Margin="11,11,0,0" HorizontalAlignment="Stretch"/>

        <Label Content="{x:Static p:Resources.Author}" Grid.Column="0" Grid.Row="1"/>
        <TextBox Text="{Binding Book.Author, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                 MaxLength="100" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>

        <Label Content="{x:Static p:Resources.Publisher}" Grid.Column="0" Grid.Row="2"/>
        <TextBox Text="{Binding Book.Publisher, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                 MaxLength="100" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>

        <Label Content="{x:Static p:Resources.PublishDate}" Grid.Column="0" Grid.Row="3"/>
        <DatePicker SelectedDate="{Binding Book.PublishDate}" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>
        
        <Label Content="{x:Static p:Resources.Isbn}" Grid.Column="0" Grid.Row="4"/>
        <TextBox Text="{Binding Book.Isbn, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                 MaxLength="14" Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>

        <Label Content="{x:Static p:Resources.Language}" Grid.Column="0" Grid.Row="5"/>
        <ComboBox ItemsSource="{Binding Source={StaticResource LanguageValues}}"
                  SelectedItem="{Binding Book.Language}" Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="2">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Converter={StaticResource LanguageToStringConverter}}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <Label Content="{x:Static p:Resources.Pages}" Grid.Column="0" Grid.Row="6"/>
        <TextBox Text="{Binding Book.Pages, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=true, NotifyOnValidationError=true}" 
                 Grid.Column="1" Grid.Row="6" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"/>

        <Label Content="{x:Static p:Resources.LendTo}" Grid.Column="0" Grid.Row="7"/>
        <TextBox IsReadOnly="True" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="7">
            <TextBox.Text>
                <MultiBinding StringFormat="{}{0} {1}" ValidatesOnNotifyDataErrors="False">
                    <Binding Path="Book.LendTo.Firstname"/>
                    <Binding Path="Book.LendTo.Lastname"/>
                </MultiBinding>
            </TextBox.Text>
        </TextBox>
        <Button Command="{Binding LendToCommand}" CommandParameter="{Binding Book, ValidatesOnNotifyDataErrors=False}" Content="{x:Static p:Resources.MoreButton}"
                MinWidth="25" Margin="7,11,0,0" Grid.Column="2" Grid.Row="7"/>
    </Grid>

</UserControl>
